/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.repository.valueObject;


import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.repository.base.CefRepoGenCtx;
import com.inspur.edp.cef.generator.repository.base.assemblerGenerator.DataTypeAssemblerGenCtx;
import com.inspur.edp.cef.generator.repository.base.assemblerGenerator.DataTypeAssemblerGenerator;
import com.inspur.edp.cef.generator.repository.valueObject.methods.ValueObjInitColumnMethodGenerator;
import com.inspur.edp.cef.repository.assembler.nesteddatatype.NestedDataTypeAssembler;
import lombok.var;

import java.util.ArrayList;

public abstract class ValueObjectAssemblerGenerator extends DataTypeAssemblerGenerator {
    protected ValueObjectAssemblerGenerator(CefRepoGenCtx repoGenCtx, IGspCommonDataType dataType) {
        super(repoGenCtx, dataType);
    }

    protected ValueObjectAssemblerGenCtx getContext() {
        return (ValueObjectAssemblerGenCtx) super.getContext();
    }


    @Override
    protected TypeInfo setParentClass() {
        var typeInfo = new TypeInfo("NestedDataTypeAssembler");
        typeInfo.setTypePackageName("com.inspur.edp.cef.repository.assembler.nesteddatatype");
        return typeInfo;
    }

    @Override
    protected ArrayList<ClassMethodGenerator> createMethodGenerators() {
        ArrayList<ClassMethodGenerator> list = super.createMethodGenerators();
        if (list == null) {
            list = new ArrayList<ClassMethodGenerator>();
        }
        list.add(getInitColumnMethodGenerator());
        // list.add(getInitReadersGenerator());
        return list;
    }

    protected abstract ValueObjInitColumnMethodGenerator getInitColumnMethodGenerator();

    // protected abstract ValueObjInitReadersGenerator  getInitReadersGenerator();

    @Override
    protected DataTypeAssemblerGenCtx createAssGenCtx() {
        return new ValueObjectAssemblerGenCtx(repoGenCtx, dataType);
    }

    @Override
    protected void beforeInitialize() {
        super.beforeInitialize();
        repoGenCtx.getCefGenCtx().setRootRepositoryType(new MediateType(repoGenCtx.getDefaultNameSpace(), getName()));
    }

    @Override
    protected void afterInitialize() {
        super.afterInitialize();
        repoGenCtx.setRootEntityAssemblerType(new MediateType(super.compileUnit.getPackageName(), getName()));
        repoGenCtx.getCefGenCtx().setRootRepositoryType(new MediateType(repoGenCtx.getDefaultNameSpace(),getName()));
    }

    @Override
    protected ArrayList<ClassPropertyGenerator> createPropertyGenerators() {

        var list = super.createPropertyGenerators();
        if (list == null) {
            list = new ArrayList<ClassPropertyGenerator>();
        }

        var propColumnMapType = getColumnMapTypePropGenerator();
        if (propColumnMapType != null) {
            list.add(getColumnMapTypePropGenerator());
        }
        return list;
    }

    protected ClassPropertyGenerator getColumnMapTypePropGenerator() {
        return null;
    }
}
